package com.usian.Controller;

import com.github.pagehelper.PageHelper;
import com.usian.pojo.*;
import com.usian.service.ItemService;
import com.usian.utils.JsonUtils;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;
    @RequestMapping("finda")
    public List<TbItem> findall(){

        return itemService.findall();
    }


    @RequestMapping("selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(@RequestParam Integer page, @RequestParam Integer rows){
      return itemService.selectTbItemAllByPage(page,rows);

    };

    @RequestMapping("insertTbItem")
    public int insertTbItem(@RequestBody TbItem tbItem,@RequestParam String desc,@RequestParam String itemParams){
        return  itemService.insertTbItem(tbItem,desc,itemParams);
    };

    @RequestMapping("deleteItemById")
    public int deleteItemById(@RequestParam String itemId){
        return itemService.deleteItemById(itemId);
    };

    @RequestMapping("preUpdateItem")
    Map<String, Object> preUpdateItem(@RequestParam Long itemId){
        return itemService.preUpdateItem(itemId);
    }
    @RequestMapping("updateTbItem")
    public int updateTbItem(@RequestBody TbItem tbItem,@RequestParam String desc,@RequestParam String itemParams){
        return  itemService.updateTbItem(tbItem,desc,itemParams);
    }

    @RequestMapping("selectItemInfo")
    public TbItem selectItemInfo(@RequestParam long itemId){
        return itemService.selectItemInfo(itemId);
    };

    @RequestMapping("selectItemDescByItemId")
    public TbItemDesc selectItemDescByItemId(@RequestParam long itemId){
        return itemService.selectItemDescByItemId(itemId);
    };

    @RequestMapping("selectTbItemParamItemByItemId")
    public TbItemParamItem selectTbItemParamItemByItemId(@RequestParam long itemId){
        return itemService.selectTbItemParamItemByItemId(itemId);
    };


}
